<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en" class="no-js">

    <head>

        <meta charset="utf-8">
        <title>厂车管理系统</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="">
        <meta name="author" content="">

        <!-- CSS -->
        <link rel='stylesheet' href="http://fonts.googleapis.com/css?family=PT+Sans:400,700">
        <link rel="stylesheet" href="assets/css/reset.css">
        <link rel="stylesheet" href="assets/css/supersized.css">
        <link rel="stylesheet" href="assets/css/style.css">


    </head>

    <body>

        <div class="page-container">
            <h1>厂车管理系统</h1>
            <form action="#" method="post" name = "LoginForm">
                <input type="text" name="username" class="username" placeholder="账号">
                <input type="password" name="password" class="password" placeholder="密码">
                <select name="roleid">
                <c:forEach var ="role" items="${sessionScope.ListAllRoles}">
                  <option value="${role.roleid}">${role.rolename}</option> 
                </c:forEach>
                </select>
                <button type="button" onClick = "LoginJudge()">登&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;录</button>
                <div class="error"><span>+</span></div>
            </form>
        </div>

        <!-- Javascript -->
        <script src="assets/js/jquery-1.8.2.min.js"></script>
        <script src="assets/js/supersized.3.2.7.min.js"></script>
        <script src="assets/js/supersized-init.js"></script>
        <script src="assets/js/scripts.js"></script>

    </body>

</html>
<script type="text/javascript">
   var xmlHttp = false;
   window.onload = function initAJAX(){
	   if(window.XMLHttpRequest){
		   xmlHttp = new XMLHttpRequest();
	   }
	   else if(window.ActiveXObject){
		   try{
			   xmlHttp = new ActiveXObject("Msxm12.XMLHTTP");
		   }catch(e){
			   try{
				   xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			   }catch(e){
				   window.alert("该浏览器不支持Ajax");
			   }
		   }
	   }
   }
</script>
<script type = "text/javascript">

	function LoginJudge() {
		var xmlHttp = false;
		var username = document.LoginForm.username.value;
		var password = document.LoginForm.password.value;
		var roleid = document.LoginForm.roleid.value;
		if (username == "") {
			alert("用户名不能为空!");
			doucment.LoginForm.username.focus();
			return;
		} else if (password == "") {
			alert("密码不能为空!");
			document.LoginForm.password.focus();
			return;
		} else {
            xmlHttp = new XMLHttpRequest();
			var url = "ifUser.do?username=" + username + "&password="
					+ password + "&roleid=" + roleid;
             xmlHttp.open("POST",url,true);
             xmlHttp.onreadystatechange = function(){
                if(xmlHttp.readyState == 4){
                    var i = xmlHttp.responseText;
                    if(i == "登录成功!")
                    { 
                    	alert(i);
                    	window.location.href="findActionColumnByUserRole.do";
                    }else{
                    	alert(i);
                    }
                }
             }
             xmlHttp.send();
		}
	}
</script>
